#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    string countAndSay(int n)
    {
        string s = "1";

        for (int i = 1; i < n; i++)
        {
            string ret;
            int len = s.size();
            for (int left = 0, right = 0; right < len;)
            {
                while (right < len && s[left] == s[right]) right++;
                ret += to_string(right - left) + s[left];
                left = right;
            }
            s = ret;
        }
        return s;
    }
};